import { Controller, UseInterceptors, Get, UploadedFile, Post, Res } from '@nestjs/common';
import { UploadService } from './upload.service';
import { FileInterceptor } from '@nestjs/platform-express';
import { join } from 'path';
@Controller('upload')
export class UploadController {
  constructor(private readonly uploadService: UploadService) { }

  @Post('/user')
  @UseInterceptors(FileInterceptor("file"))
  create(@UploadedFile() file, @Res() res) {

    let normalizedPath = file.path.replace(/\\/g, '/');
    console.log(normalizedPath)
    let relativePath = normalizedPath.split('images')[1];
    let newpath = '/deliciousimg' + relativePath
    res.status(200).send({
      path: newpath,
      code: 200,
      message: '上传成功'
    })
  }


}
